﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.Control.News
{
    public partial class UsrListNews : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            HCDataContext dc = new HCDataContext();
            Trang trang = C.TrangController.GetCurrentTrangOrInsert();

            var result = from a in dc.News
                         where //a.TrangID == trang.TrangID
                            a.DisplayInLang == C.LanguageController.GetLanguageCurrent()
                         orderby a.DateCreated descending
                         select a;

            int itemPerPage = 10;
            int curPage = M.UrlQuery.page.HasValue ? M.UrlQuery.page.Value : 1;
            litPaging.Text = M.Common.GetPaging(result.Count(), itemPerPage, ref curPage);

            grdNews.DataSource = result.Skip((curPage - 1) * itemPerPage).Take(itemPerPage).ToList();
            grdNews.DataBind();
        }

        protected void grdNews_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                
            }
        }
    }
}